import Vue from 'vue'
import routes from './routes'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
//重写VueRouter.prototype原型对象身上的push方法
const originPush = VueRouter.prototype.push
VueRouter.prototype.push = function(location, resolve, reject) {
 
  if(resolve || reject) return originPush.call(this, location, resolve, reject)
   // 判断如果没有指定回调函数, 通过call调用源函数并使用catch来处理错误
  return originPush.call(this, location).catch(err => err)
}
const router = new VueRouter({
  mode: 'history',
  routes
})

export default router